package com.itheima.result;

import com.itheima.exception.BussinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author father
 * @date 2021/12/1
 * @apiNote
 **/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R ex(SQLIntegrityConstraintViolationException e){
        log.error(e.getMessage());
        return R.error("分类已存在，无法重复添加...");
    }

   @ExceptionHandler(BussinessException.class)
   public R et(BussinessException e){
       log.error(e.getMessage());
       return R.error(e.getMessage());
}

 /*@ExceptionHandler(Exception.class)
    public R eh(Exception e){
        log.error(e.getMessage());
        return R.error("系统出错！");
    }*/
}
